from public.config import data_path
from public.log import public_logger
import ctypes


class LibTool:
    def __init__(self, path):
        self._dll = ctypes.CDLL(path)

    def __getattr__(self, item):
        def wrapper(*args):
            public_logger.info(f'执行 {item}{args}')
            func = getattr(self._dll, item)
            try:
                return func(*args)
            except Exception as e:
                public_logger.error(f'执行 {item} 失败：{e}')
                raise

        return wrapper


class MeiFile(LibTool):
    def __init__(self):
        super().__init__(data_path('lib_tool', 'lib_mei_file.dll'))
